package com.hdoit.ares.logical.share.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.share.dao.ITrainCourseDao;
import com.hdoit.ares.logical.share.model.TrainCourse;
import com.hdoit.ares.logical.share.model.ViewTime;
import com.hdoit.ares.logical.share.service.ITrainCourseService;
import com.hdoit.ares.logical.share.service.IViewTimeService;
import com.hdoit.ares.logical.viewmodel.share.TrainCourseSearch;
import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.enums.ModelStatus;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.CommonUtils;
/**
 * @author      wangxuexue
 * @email       
 * @createtime  2017年11月19日 16:42:52
 * @comment
 */
@Component
public class TrainCourseServiceImpl extends SuperService<TrainCourse> implements ITrainCourseService{

	private IViewTimeService viewTimeService;
	
	public IViewTimeService getViewTimesService() {
		return viewTimeService;
	}

	@Resource
	public void setViewTimesService(IViewTimeService viewTimeService) {
		this.viewTimeService = viewTimeService;
	}

	private ITrainCourseDao trainCourseDao;
	
	public ITrainCourseDao getTrainCourseDao() {
		return trainCourseDao;
	}
	
	@Resource
	public void setTrainCourseDao(ITrainCourseDao trainCourseDao) {
		this.trainCourseDao = trainCourseDao;
	}

	@Override
	public List<TrainCourse> queryLimittrainCourses(String courseType,
			String courseKinds) {
		
		return trainCourseDao.queryLimittrainCourses(courseType, courseKinds);
	}

	@Override
	public List<TrainCourse> queryAlltrainCourses(String courseType,
			String courseKinds) {
		
		return trainCourseDao.queryAlltrainCourses(courseType, courseKinds);
	}

	@Override
	public TrainCourse querytrainCourseDetails(String id) {
		
		return trainCourseDao.querytrainCourseDetails(id);
	}

	@Override
	public List<TrainCourse> queryOthertrainCourses(String id, String courseType,
			String courseKinds) {
		
		return trainCourseDao.queryOthertrainCourses(id, courseType, courseKinds);
	}

	@Override
	public int queryTrainCourseCount(TrainCourseSearch trainCourseSearch) {
		
		return trainCourseDao.queryTrainCourseCount(trainCourseSearch);
	}

	@Override
	public List<TrainCourse> queryTrainCourseList(
			TrainCourseSearch trainCourseSearch, PagerModel pagerModel) {
		
		return trainCourseDao.queryTrainCourseList(trainCourseSearch, pagerModel);
	}

	@Override
	public TrainCourse queryTrainCourseModel(String key) {
		
		return trainCourseDao.queryTrainCourseModel(key);
	}
	
	@Override
	public boolean applyChange(TrainCourse trainCourse) {
		if(super.applyChange(trainCourse)){
			
			if(ModelStatus.add.equals(trainCourse.getModelStatus())){
				
					ViewTime viewTime = new ViewTime();
					viewTime.setId(CommonUtils.getKeyId());
					viewTime.setShareid(trainCourse.getId());
					viewTime.setType("train");
					viewTime.setViewtimes(0);
					viewTime.setDeleteMark(trainCourse.getDeleteMark());
					return viewTimeService.addModel(viewTime);	
			}
			
			return true;
	}
		
		return false;
	}

	@Override
	public int updateVideoById(String id) {
		
		return trainCourseDao.updateVideoById(id);
	}

	@Override
	public int updateSmallPicById(String id) {
		
		return trainCourseDao.updateSmallPicById(id);
	}
	
}